﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Charting;

namespace DIST.LR.ZHJG.Controls.Chart
{
    public partial class ucStackedBar : UserControl
    {
        public ucStackedBar()
        {
            InitializeComponent();
        }

        public void Binding<T>(StackInfo<T> info)
        {
           
            this.RadChart1.SeriesMappings.Clear();
            foreach (StackValue stack in info.StackValues)
            {
                SeriesMapping mapping = new SeriesMapping();
                mapping.SeriesDefinition = new HorizontalStackedBarSeriesDefinition()
                {
                    ShowItemToolTips = true,
                    StackGroupName = stack.StackGroupName,
                    ShowItemLabels = true, 
                    LabelSettings = new BarLabelSettings()
                    {
                        //Distance = 10,
                        LabelDisplayMode = Telerik.Windows.Controls.Charting.LabelDisplayMode.Auto,
                        ShowZeroValueLabels = false,
                        ShowConnectors = false
                    },
                    Appearance = new SeriesAppearanceSettings() { Fill=stack.Color },
                    SeriesItemLabelStyle = this.Resources["SeriesLabelStyle"] as Style,
                    //ItemLabelFormat = "#%{p0}"
                };
                mapping.LegendLabel = stack.LableName;
                mapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.YValue, FieldName = stack.ValueName });
                mapping.ItemMappings.Add(new ItemMapping() { DataPointMember = DataPointMember.XCategory, FieldName = stack.XCategoryName });
                this.RadChart1.SeriesMappings.Add(mapping);
            }

            this.RadChart1.ItemsSource = info.DataSource;
        }
    }

    public class StackInfo<T>
    {
        public StackInfo()
        {
            this.StackValues = new List<StackValue>();
            //this.DataSource = new List<T>();
        }
        public List<StackValue> StackValues { get; set; }
        //public List<double> DoubleValues { get; set; }

        public List<T> DataSource { get; set; }
        //public List<string> XLables { get; set; }
    }

    public class StackValue : BarValue
    {
        //public int Index { get; set; }
        public string StackGroupName { get; set; }
    }
}
